<template>
    <div class="container">
        <div class="code-review">
            <div class="img-center">
                <img v-if="imgUrl" :src="imgUrl" alt="" />
                <img v-else src="../../../assets/images/my/upload_img.png" alt="" />
            </div>
        </div>
        <div class="upload">
            <van-uploader :after-read="afterRead">
                <van-button :disabled="isLoading" icon="plus" type="primary">上传二维码</van-button>
            </van-uploader>
        </div>
    </div>
</template>
<script>
    import { uploadWxWorkQrCode } from "@/api/common";
    import { Toast } from "vant";
    export default {
        data() {
            return {
                isLoading: false,
                imgUrl: "",
            };
        },
        created() {
            this.imgUrl = this.$getUserInfo().wxWorkQrcode || "";
        },
        components: {},
        methods: {
            async afterRead(fileInfo) {
                this.isLoading = true;
                let res = await uploadWxWorkQrCode({ file: fileInfo.file });
                if (res && res.code === 1) {
                    Toast(res.msg);
                    this.imgUrl = fileInfo.content;
                }
                this.isLoading = false;
            },
        },
    };
</script>
<style lang="scss" scoped>
    .container {
        .code-review {
            min-width: 100%;
            min-height: 200px;
            .img-center {
                width: 200px;
                height: 200px;
                margin: 0 auto;
                img {
                    width: 100%;
                    height: 100%;
                    object-fit: contain;
                }
            }
        }
        .upload {
            margin-top: 20px;
            width: 100%;
            text-align: center;
        }
    }
</style>